$(function() {
	validateRule();
	$('#btnSubmit').click(function(){
		login() ;
	}) ;
});

$(document).keyup(function(event) {
	if (event.keyCode == 13) {
		login();
	}
});

function login() {
	$.modal.loading($("#btnSubmit").data("loading"));
	var username = $.common.trim($("input[name='username']").val());
	var password = $.common.trim($("input[name='password']").val());
	var validateCode = $("input[name='validateCode']").val();
	var rememberMe = true ;
	//获取系统加密方式
	var str  ="username="+username+"&password="+password;
	username = encryptStr(username);
	password = encryptStr(password);
	str = encryptStr(str);
	$.ajax({
		type : "post",
		url : ctx + "login",
		data : {
			"content":str,
			"username" : username,
			"password" : password,
			"validateCode" : validateCode,
			"rememberMe" : rememberMe
		},
		success : function(r) {
			if (r.code == 0) {
				location.href = ctx + 'index';
			} else {
				$.modal.closeLoading();
				$('.imgcode').click();
				$(".code").val("");
				$.modal.msg(r.msg);
			}
		}
	});
}

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			username : {
				required : true
			},
			password : {
				required : true
			}
		},
		messages : {
			username : {
				required : icon + "请输入您的用户名",
			},
			password : {
				required : icon + "请输入您的密码",
			}
		}
	})
}
